<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- NewPage -->
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html" charset="UTF-8">
<title>EventHandler (Apache Commons Math 3.3 API)</title>
<link rel="stylesheet" type="text/css" href="../../../../../../stylesheet.css" title="Style">
</head>
<body>
<script type="text/javascript"><!--
    if (location.href.indexOf('is-external=true') == -1) {
        parent.document.title="EventHandler (Apache Commons Math 3.3 API)";
    }
//-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar_top">
<!--   -->
</a><a href="#skip-navbar_top" title="Skip navigation links"></a><a name="navbar_top_firstrow">
<!--   -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="class-use/EventHandler.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../../help-doc.html">Help</a></li>
</ul>
<div class="aboutLanguage"><em><script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script></em></div>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../../../org/apache/commons/math3/ode/events/EventFilter.html" title="class in org.apache.commons.math3.ode.events"><span class="strong">Prev Class</span></a></li>
<li><a href="../../../../../../org/apache/commons/math3/ode/events/EventHandler.Action.html" title="enum in org.apache.commons.math3.ode.events"><span class="strong">Next Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../../../index.html?org/apache/commons/math3/ode/events/EventHandler.html" target="_top">Frames</a></li>
<li><a href="EventHandler.html" target="_top">No Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../../../allclasses-noframe.html">All Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
  allClassesLink = document.getElementById("allclasses_navbar_top");
  if(window==top) {
    allClassesLink.style.display = "block";
  }
  else {
    allClassesLink.style.display = "none";
  }
  //-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li><a href="#nested_class_summary">Nested</a>&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method_summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method_detail">Method</a></li>
</ul>
</div>
<a name="skip-navbar_top">
<!--   -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<div class="subTitle">org.apache.commons.math3.ode.events</div>
<h2 title="Interface EventHandler" class="title">Interface EventHandler</h2>
</div>
<div class="contentContainer">
<div class="description">
<ul class="blockList">
<li class="blockList">
<dl>
<dt>All Known Implementing Classes:</dt>
<dd><a href="../../../../../../org/apache/commons/math3/ode/events/EventFilter.html" title="class in org.apache.commons.math3.ode.events">EventFilter</a></dd>
</dl>
<hr>
<br>
<pre>public interface <span class="strong">EventHandler</span></pre>
<div class="block">This interface represents a handler for discrete events triggered
 during ODE integration.

 <p>Some events can be triggered at discrete times as an ODE problem
 is solved. This occurs for example when the integration process
 should be stopped as some state is reached (G-stop facility) when the
 precise date is unknown a priori, or when the derivatives have
 discontinuities, or simply when the user wants to monitor some
 states boundaries crossings.
 </p>

 <p>These events are defined as occurring when a <code>g</code>
 switching function sign changes.</p>

 <p>Since events are only problem-dependent and are triggered by the
 independent <i>time</i> variable and the state vector, they can
 occur at virtually any time, unknown in advance. The integrators will
 take care to avoid sign changes inside the steps, they will reduce
 the step size when such an event is detected in order to put this
 event exactly at the end of the current step. This guarantees that
 step interpolation (which always has a one step scope) is relevant
 even in presence of discontinuities. This is independent from the
 stepsize control provided by integrators that monitor the local
 error (this event handling feature is available for all integrators,
 including fixed step ones).</p></div>
<dl><dt><span class="strong">Since:</span></dt>
  <dd>1.2</dd>
<dt><span class="strong">Version:</span></dt>
  <dd>$Id: EventHandler.java 1451658 2013-03-01 17:36:46Z luc $</dd></dl>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- ======== NESTED CLASS SUMMARY ======== -->
<ul class="blockList">
<li class="blockList"><a name="nested_class_summary">
<!--   -->
</a>
<h3>Nested Class Summary</h3>
<table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Nested Class Summary table, listing nested classes, and an explanation">
<caption><span>Nested Classes</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Interface and Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static class&nbsp;</code></td>
<td class="colLast"><code><strong><a href="../../../../../../org/apache/commons/math3/ode/events/EventHandler.Action.html" title="enum in org.apache.commons.math3.ode.events">EventHandler.Action</a></strong></code>
<div class="block">Enumerate for actions to be performed when an event occurs.</div>
</td>
</tr>
</table>
</li>
</ul>
<!-- ========== METHOD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="method_summary">
<!--   -->
</a>
<h3>Method Summary</h3>
<table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation">
<caption><span>Methods</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Method and Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code><a href="../../../../../../org/apache/commons/math3/ode/events/EventHandler.Action.html" title="enum in org.apache.commons.math3.ode.events">EventHandler.Action</a></code></td>
<td class="colLast"><code><strong><a href="../../../../../../org/apache/commons/math3/ode/events/EventHandler.html#eventOccurred(double, double[], boolean)">eventOccurred</a></strong>(double&nbsp;t,
             double[]&nbsp;y,
             boolean&nbsp;increasing)</code>
<div class="block">Handle an event and choose what to do next.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>double</code></td>
<td class="colLast"><code><strong><a href="../../../../../../org/apache/commons/math3/ode/events/EventHandler.html#g(double, double[])">g</a></strong>(double&nbsp;t,
 double[]&nbsp;y)</code>
<div class="block">Compute the value of the switching function.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><strong><a href="../../../../../../org/apache/commons/math3/ode/events/EventHandler.html#init(double, double[], double)">init</a></strong>(double&nbsp;t0,
    double[]&nbsp;y0,
    double&nbsp;t)</code>
<div class="block">Initialize event handler at the start of an ODE integration.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><strong><a href="../../../../../../org/apache/commons/math3/ode/events/EventHandler.html#resetState(double, double[])">resetState</a></strong>(double&nbsp;t,
          double[]&nbsp;y)</code>
<div class="block">Reset the state prior to continue the integration.</div>
</td>
</tr>
</table>
</li>
</ul>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ============ METHOD DETAIL ========== -->
<ul class="blockList">
<li class="blockList"><a name="method_detail">
<!--   -->
</a>
<h3>Method Detail</h3>
<a name="init(double, double[], double)">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>init</h4>
<pre>void&nbsp;init(double&nbsp;t0,
        double[]&nbsp;y0,
        double&nbsp;t)</pre>
<div class="block">Initialize event handler at the start of an ODE integration.
 <p>
 This method is called once at the start of the integration. It
 may be used by the event handler to initialize some internal data
 if needed.
 </p></div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>t0</code> - start value of the independent <i>time</i> variable</dd><dd><code>y0</code> - array containing the start value of the state vector</dd><dd><code>t</code> - target time for the integration</dd></dl>
</li>
</ul>
<a name="g(double, double[])">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>g</h4>
<pre>double&nbsp;g(double&nbsp;t,
       double[]&nbsp;y)</pre>
<div class="block">Compute the value of the switching function.

 <p>The discrete events are generated when the sign of this
 switching function changes. The integrator will take care to change
 the stepsize in such a way these events occur exactly at step boundaries.
 The switching function must be continuous in its roots neighborhood
 (but not necessarily smooth), as the integrator will need to find its
 roots to locate precisely the events.</p>
 <p>Also note that the integrator expect that once an event has occurred,
 the sign of the switching function at the start of the next step (i.e.
 just after the event) is the opposite of the sign just before the event.
 This consistency between the steps <string>must</strong> be preserved,
 otherwise <a href="../../../../../../org/apache/commons/math3/exception/NoBracketingException.html" title="class in org.apache.commons.math3.exception"><code>exceptions</code></a> related to root not being bracketed will occur.</p>
 <p>This need for consistency is sometimes tricky to achieve. A typical
 example is using an event to model a ball bouncing on the floor. The first
 idea to represent this would be to have <code>g(t) = h(t)</code> where h is the
 height above the floor at time <code>t</code>. When <code>g(t)</code> reaches 0, the
 ball is on the floor, so it should bounce and the typical way to do this is
 to reverse its vertical velocity. However, this would mean that before the
 event <code>g(t)</code> was decreasing from positive values to 0, and after the
 event <code>g(t)</code> would be increasing from 0 to positive values again.
 Consistency is broken here! The solution here is to have <code>g(t) = sign
 * h(t)</code>, where sign is a variable with initial value set to <code>+1</code>. Each
 time <a href="../../../../../../org/apache/commons/math3/ode/events/EventHandler.html#eventOccurred(double, double[], boolean)"><code>eventOccurred</code></a> is called,
 <code>sign</code> is reset to <code>-sign</code>. This allows the <code>g(t)</code>
 function to remain continuous (and even smooth) even across events, despite
 <code>h(t)</code> is not. Basically, the event is used to <em>fold</em> <code>h(t)</code>
 at bounce points, and <code>sign</code> is used to <em>unfold</em> it back, so the
 solvers sees a <code>g(t)</code> function which behaves smoothly even across events.</p></div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>t</code> - current value of the independent <i>time</i> variable</dd><dd><code>y</code> - array containing the current value of the state vector</dd>
<dt><span class="strong">Returns:</span></dt><dd>value of the g switching function</dd></dl>
</li>
</ul>
<a name="eventOccurred(double, double[], boolean)">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>eventOccurred</h4>
<pre><a href="../../../../../../org/apache/commons/math3/ode/events/EventHandler.Action.html" title="enum in org.apache.commons.math3.ode.events">EventHandler.Action</a>&nbsp;eventOccurred(double&nbsp;t,
                                double[]&nbsp;y,
                                boolean&nbsp;increasing)</pre>
<div class="block">Handle an event and choose what to do next.

 <p>This method is called when the integrator has accepted a step
 ending exactly on a sign change of the function, just <em>before</em>
 the step handler itself is called (see below for scheduling). It
 allows the user to update his internal data to acknowledge the fact
 the event has been handled (for example setting a flag in the <a href="../../../../../../org/apache/commons/math3/ode/FirstOrderDifferentialEquations.html" title="interface in org.apache.commons.math3.ode"><code>differential equations</code></a> to switch the derivatives computation in
 case of discontinuity), or to direct the integrator to either stop
 or continue integration, possibly with a reset state or derivatives.</p>

 <ul>
   <li>if <a href="../../../../../../org/apache/commons/math3/ode/events/EventHandler.Action.html#STOP"><code>EventHandler.Action.STOP</code></a> is returned, the step handler will be called
   with the <code>isLast</code> flag of the <a href="../../../../../../org/apache/commons/math3/ode/sampling/StepHandler.html#handleStep(org.apache.commons.math3.ode.sampling.StepInterpolator, boolean)"><code>handleStep</code></a>
   method set to true and the integration will be stopped,</li>
   <li>if <a href="../../../../../../org/apache/commons/math3/ode/events/EventHandler.Action.html#RESET_STATE"><code>EventHandler.Action.RESET_STATE</code></a> is returned, the <a href="../../../../../../org/apache/commons/math3/ode/events/EventHandler.html#resetState(double, double[])"><code>resetState</code></a> method will be called once the step handler has
   finished its task, and the integrator will also recompute the
   derivatives,</li>
   <li>if <a href="../../../../../../org/apache/commons/math3/ode/events/EventHandler.Action.html#RESET_DERIVATIVES"><code>EventHandler.Action.RESET_DERIVATIVES</code></a> is returned, the integrator
   will recompute the derivatives,
   <li>if <a href="../../../../../../org/apache/commons/math3/ode/events/EventHandler.Action.html#CONTINUE"><code>EventHandler.Action.CONTINUE</code></a> is returned, no specific action will
   be taken (apart from having called this method) and integration
   will continue.</li>
 </ul>

 <p>The scheduling between this method and the <a href="../../../../../../org/apache/commons/math3/ode/sampling/StepHandler.html" title="interface in org.apache.commons.math3.ode.sampling"><code>StepHandler</code></a> method <a href="../../../../../../org/apache/commons/math3/ode/sampling/StepHandler.html#handleStep(org.apache.commons.math3.ode.sampling.StepInterpolator, boolean)"><code>handleStep(interpolator, isLast)</code></a> is to call this method first and
 <code>handleStep</code> afterwards. This scheduling allows the integrator to
 pass <code>true</code> as the <code>isLast</code> parameter to the step
 handler to make it aware the step will be the last one if this method
 returns <a href="../../../../../../org/apache/commons/math3/ode/events/EventHandler.Action.html#STOP"><code>EventHandler.Action.STOP</code></a>. As the interpolator may be used to navigate back
 throughout the last step (as <a href="../../../../../../org/apache/commons/math3/ode/sampling/StepNormalizer.html" title="class in org.apache.commons.math3.ode.sampling"><code>StepNormalizer</code></a>
 does for example), user code called by this method and user
 code called by step handlers may experience apparently out of order values
 of the independent time variable. As an example, if the same user object
 implements both this <a href="../../../../../../org/apache/commons/math3/ode/events/EventHandler.html" title="interface in org.apache.commons.math3.ode.events"><code>EventHandler</code></a> interface and the
 <a href="../../../../../../org/apache/commons/math3/ode/sampling/FixedStepHandler.html" title="interface in org.apache.commons.math3.ode.sampling"><code>FixedStepHandler</code></a>
 interface, a <em>forward</em> integration may call its
 <code>eventOccurred</code> method with t = 10 first and call its
 <code>handleStep</code> method with t = 9 afterwards. Such out of order
 calls are limited to the size of the integration step for <a href="../../../../../../org/apache/commons/math3/ode/sampling/StepHandler.html" title="interface in org.apache.commons.math3.ode.sampling"><code>variable step handlers</code></a> and
 to the size of the fixed step for <a href="../../../../../../org/apache/commons/math3/ode/sampling/FixedStepHandler.html" title="interface in org.apache.commons.math3.ode.sampling"><code>fixed step handlers</code></a>.</p></div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>t</code> - current value of the independent <i>time</i> variable</dd><dd><code>y</code> - array containing the current value of the state vector</dd><dd><code>increasing</code> - if true, the value of the switching function increases
 when times increases around event (note that increase is measured with respect
 to physical time, not with respect to integration which may go backward in time)</dd>
<dt><span class="strong">Returns:</span></dt><dd>indication of what the integrator should do next, this
 value must be one of <a href="../../../../../../org/apache/commons/math3/ode/events/EventHandler.Action.html#STOP"><code>EventHandler.Action.STOP</code></a>, <a href="../../../../../../org/apache/commons/math3/ode/events/EventHandler.Action.html#RESET_STATE"><code>EventHandler.Action.RESET_STATE</code></a>,
 <a href="../../../../../../org/apache/commons/math3/ode/events/EventHandler.Action.html#RESET_DERIVATIVES"><code>EventHandler.Action.RESET_DERIVATIVES</code></a> or <a href="../../../../../../org/apache/commons/math3/ode/events/EventHandler.Action.html#CONTINUE"><code>EventHandler.Action.CONTINUE</code></a></dd></dl>
</li>
</ul>
<a name="resetState(double, double[])">
<!--   -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>resetState</h4>
<pre>void&nbsp;resetState(double&nbsp;t,
              double[]&nbsp;y)</pre>
<div class="block">Reset the state prior to continue the integration.

 <p>This method is called after the step handler has returned and
 before the next step is started, but only when <a href="../../../../../../org/apache/commons/math3/ode/events/EventHandler.html#eventOccurred(double, double[], boolean)"><code>eventOccurred(double, double[], boolean)</code></a> has itself returned the <a href="../../../../../../org/apache/commons/math3/ode/events/EventHandler.Action.html#RESET_STATE"><code>EventHandler.Action.RESET_STATE</code></a>
 indicator. It allows the user to reset the state vector for the
 next step, without perturbing the step handler of the finishing
 step. If the <a href="../../../../../../org/apache/commons/math3/ode/events/EventHandler.html#eventOccurred(double, double[], boolean)"><code>eventOccurred(double, double[], boolean)</code></a> never returns the <a href="../../../../../../org/apache/commons/math3/ode/events/EventHandler.Action.html#RESET_STATE"><code>EventHandler.Action.RESET_STATE</code></a> indicator, this function will never be called, and it is
 safe to leave its body empty.</p></div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>t</code> - current value of the independent <i>time</i> variable</dd><dd><code>y</code> - array containing the current value of the state vector
 the new state should be put in the same array</dd></dl>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<!-- ========= END OF CLASS DATA ========= -->
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar_bottom">
<!--   -->
</a><a href="#skip-navbar_bottom" title="Skip navigation links"></a><a name="navbar_bottom_firstrow">
<!--   -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="class-use/EventHandler.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../../help-doc.html">Help</a></li>
</ul>
<div class="aboutLanguage"><em><script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script></em></div>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../../../org/apache/commons/math3/ode/events/EventFilter.html" title="class in org.apache.commons.math3.ode.events"><span class="strong">Prev Class</span></a></li>
<li><a href="../../../../../../org/apache/commons/math3/ode/events/EventHandler.Action.html" title="enum in org.apache.commons.math3.ode.events"><span class="strong">Next Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../../../index.html?org/apache/commons/math3/ode/events/EventHandler.html" target="_top">Frames</a></li>
<li><a href="EventHandler.html" target="_top">No Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../../../allclasses-noframe.html">All Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
  allClassesLink = document.getElementById("allclasses_navbar_bottom");
  if(window==top) {
    allClassesLink.style.display = "block";
  }
  else {
    allClassesLink.style.display = "none";
  }
  //-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li><a href="#nested_class_summary">Nested</a>&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method_summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method_detail">Method</a></li>
</ul>
</div>
<a name="skip-navbar_bottom">
<!--   -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
<p class="legalCopy"><small>Copyright &#169; 2003&#x2013;2014 <a href="http://www.apache.org/">The Apache Software Foundation</a>. All rights reserved.</small></p>
</body>
</html>
